// by Xeno
private ["_unit", "_caller", "_chatfunc", "_height", "_speed", "_hasbox", "_str", "_nobjs", "_box","_unitType","_ammo_vec"];

if (!X_Client) exitWith {};

_unit = _this select 0;
_caller = _this select 1;

_chatfunc = {
	if (vehicle (_this select 1) == (_this select 0)) then {
		[(_this select 0), _this select 2] call XfVehicleChat;
	} else {
		[_this select 1, _this select 2] call XfSideChat;
	};
};

if (_unit == _caller) then {_unit = d_curvec_dialog};
_unitType = typeof _unit;

_ammo_vec = _unit getVariable "d_ammotype";
if (isnil "_ammo_vec") then { _ammo_vec = false; };
// If the vehicle is not one of those which can load boxes... we don't look further.
if (!(_unitType in d_check_ammo_load_vecs) && !_ammo_vec) exitWith {[_unit,localize "MSG_DOM_VECNOTAMMOVEC"] call XfVehicleChat};

_height = _unit call XfGetHeight;
if (_height > 3) exitWith {[_unit,localize "MSG_DOM_VECTOOHIGHTOLOADBOX"] call XfVehicleChat};
_speed = speed _unit;
if (_speed > 3) exitWith {[_unit,localize "MSG_DOM_VECTOOFASTTOLOADBOX"] call XfVehicleChat};

_hasbox = _unit getVariable "d_ammobox";
if (isNil "_hasbox") then {_hasbox = false};
if (_hasbox) exitWith {[_unit, _caller, localize "MSG_DOM_VECALREADYHASBOX"] call _chatfunc};

_time_next = _unit getVariable "d_ammobox_next";
if (isNil "_time_next") then {_time_next = -1};
if (_time_next > time) exitWith {[_unit, _caller, format [localize "MSG_DOM_VECLOADBOXWAIT",round (_time_next - time)]] call _chatfunc};

_nobjs = nearestObjects [_unit,d_all_ammoboxes, 20];
if (count _nobjs == 0) exitWith {[_unit, _caller, localize "MSG_DOM_VECNONEARBOX"] call _chatfunc};
_box = _nobjs select 0;
[_unit, _caller, localize "MSG_DOM_VECLOADINGBOX"] call _chatfunc;
["d_r_box", [position _box]] call XNetCallEvent;
_unit setVariable ["d_ammobox", true, true];
_time_next = time + d_drop_ammobox_time;
_unit setVariable ["d_ammobox_next", _time_next, true];
[_unit, _caller, localize "MSG_DOM_VECBOXLOADED"] call _chatfunc;